<?php
namespace App\Utils;

class StrUtils {

    /**
     * 生成随机数字字符串
     */
    public static function randDigit(int $len = 6) : string {
        return str_pad(strval(mt_rand(0, pow(10, $len)-1)), $len, '0', STR_PAD_LEFT);
    }

    /**
     * 生成uuid
     */
    public static function genUuid() {
        $chars = md5(uniqid(mt_rand(), true));  
        $uuid = substr ( $chars, 0, 8 ) . '-'
                . substr ( $chars, 8, 4 ) . '-' 
                . substr ( $chars, 12, 4 ) . '-'
                . substr ( $chars, 16, 4 ) . '-'
                . substr ( $chars, 20, 12 );  
        return $uuid;
    }
}